﻿/*
 * File: NvshuWord.cs
 * Project: NvshuScrpits
 * File Created: Monday, 24th December 2018 3:43:44 pm
 * Author: shpkng (shpkng@gmail.com)
 * Organization: Communication University of China
 * License: GPL
 * -----
 * Last Modified: Monday, 7th January 2019 3:52:46 pm
 * Modified By: shpkng (shpkng@gmail.com)
 * -----
 * Valar Morghulis.
 */

//用来控制演示场景中单个字符GameObject的行为
using System.Collections;
using System.Collections.Generic;
using Unity.Collections;
using UnityEngine;
using UnityEngine.UI;

public class NvshuWord : MonoBehaviour
{

    RectTransform trans;

    [SerializeField] Transform tMod;
    //速度就是下落的速度
    //这里加了一个velocity的访问器大概是为了装x
    [SerializeField] Vector3 速度 = new Vector3 (0, -1);
    public Vector3 velocity { get { return 速度; } set { 速度 = value; } }

    //整个NvshuWord对象对应的字符编号
    [SerializeField] int 字符编号 = 1;

    [SerializeField] float 视野边缘 = 0.7f;

    #region  动作相关

    bool isUsing = false;
    bool pause = false;
    float timeCount = 0;
    [SerializeField] float thresh = 0.1f;
    #endregion

    //扇面上的控制脚本
    FanAnimator fAnim;

    int index = 0;

    private void Start ()
    {
        fAnim = GetComponent<FanAnimator> ();
        trans = GetComponent<RectTransform> ();
    }

    private void Update ()
    {
        tMod.eulerAngles += new Vector3(0,60,0) *Time.deltaTime;

        //脱离触碰则开始计时
        if (!isUsing)
            timeCount += Time.deltaTime;
        else
        {
            timeCount = 0;
            pause = true;
            ShowDetail ();
        }

        //脱离触碰的时间超过阈值
        if (timeCount > thresh)
        {
            CloseDetail ();
            pause = false;
        }

        if (!pause)
        {
            trans.position += velocity * Time.deltaTime;
        }

        isUsing = false;
    }

    public void Use ()
    {
        isUsing = true;
    }

    public void ShowDetail ()
    {
        fAnim.Open ();
    }

    public void CloseDetail ()
    {
        fAnim.Close ();
    }
}